﻿using System;
using System.IO;
using System.Web;
using System.Text;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
//using System.Data.Objects;

//using System.Runtime.Serialization.Json;
using System.Linq;

namespace VideoClassLibrary.Extension

{
    public static class JsonHelper
    {

        public static string ToJsonItem(this object item)
        {
            return JsonConvert.SerializeObject(item, new IsoDateTimeConverter());
        }


        public static T FromJsonTo<T>(this string jsonString)
        {
            try
            {
                return JsonConvert.DeserializeObject<T>(jsonString, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });

            }
            catch (Exception e)
            {
                
                throw e;
            }
        }

        //public static string ToTraceString<T>(this IQueryable<T> t)
        //{
        //    ObjectQuery<T> oqt = t as ObjectQuery<T>;
        //    if (oqt != null)
        //        return oqt.ToTraceString();
        //    return "";
        //}



    }
}

